import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/8/29.
 */
public class GenTool {
    public static void gen(){
        try {
            List<String> warnings = new ArrayList<String>();
            File configurationFile = new File(GenTool.class.getResource("/generatorConfig.xml").toURI());
            ConfigurationParser cp = new ConfigurationParser(warnings);
            Configuration config = cp.parseConfiguration(configurationFile);

            DefaultShellCallback shellCallback = new DefaultShellCallback(true);
            MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
            myBatisGenerator.generate(null);
            System.out.println("generator success!");
        } catch (Exception e) {
            System.out.println("generator error");
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws Exception {
        System.out.println("start generator...");

        gen();
    }
}
